package com.daydayup.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2019/3/28/028.
 */
public class StreamTest {

    public static void main(String[] args) {
        List<Student> students = new ArrayList<Student>();
        for (int i = 0; i < 10; i++) {
            Student student = new Student();
            student.setName("张三" + i);
            student.setAge(i);
            students.add(student);
        }
//        Student student = new Student();
//        student.setName("null");
//        System.out.println(student.getAge()+"------------");
//        students.add(student);

        int agess = students.stream().mapToInt(e -> e.getAge()).sum();
        System.out.println(agess + "=============");

        List<Student> stus = students.stream().filter(e -> e.getAge() > 5).collect(Collectors.toList());
        System.out.println(stus.toString());

        int count = students.stream().filter(e -> e.getAge() > 5).collect(Collectors.toList()).size();
        System.out.println(count);

        int ages = students.stream().filter(e -> e.getAge() > 5).mapToInt(e -> e.getAge()).sum();
        System.out.println(ages);

        List<Student> stus1 = students.stream().limit(3).collect(Collectors.toList());
        System.out.println(stus1);

        List<Student> stus2 = students.stream().filter(e -> e.getAge() >5).sorted((a,b) -> b.getAge().compareTo(a.getAge())).collect(Collectors.toList());
        System.out.println("stus2=" + stus2);
    }
}
